#include "process.h"

const char* str = "|/-\\";

//不能一次将进度条打印完毕，否则无法平滑的和场景结合
//应该根据推进比例rate, 自动地打一次
void process(double rate)
{
    static char bar[SIZE] = {0};
    static int cnt = 0;
    int num = strlen(str);
    if(rate <= MAX_RATE && rate >= 0) //判断比例是否合法
    {
        cnt++;
        cnt %= num;
        printf("加载中...[%-100s][%.1lf%%][%c]\r", bar, rate, str[cnt]);
        fflush(stdout);
        if(rate < MAX_RATE-1)
        {
            bar[(int)rate++] = STYLE_BODY;
            bar[(int)rate] = STYLE_HEAD;
        }
        else
        {
            bar[(int)rate] = STYLE_BODY;
        }
    }
}

